import { defineStore } from "pinia"
import store from "store2"

export default defineStore("user", {
  state(): {
    token: string | null
    refreshToken: string | null
    expire: number
    refreshExpire: number
    userInfo: getInfoType
  } {
    return {
      token: null,
      refreshToken: null,
      expire: 0,
      refreshExpire: 0,
      userInfo: {} as getInfoType
    }
  },

  actions: {
  },

  // 开启持久化
  persist: {
    enabled: true, // 启用
    strategies: [
      {
        key: "userInfo",
        // storage 可选localStorage或sessionStorage
        storage: localStorage,
        // 给指定数据持久化
        paths: ["userInfo"]
      }
    ]
  }
})
